﻿using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;

using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_DiaoCha_Wenti : SystemBBasePage
{

    private string sql = "";
    private int text = Convert.ToInt32(PageIndex.pageIndex);
    private Maticsoft.BLL.vote_question voqu = new Maticsoft.BLL.vote_question();

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.wenTi();
    }

    private void delWenti(int id)
    {
        this.voqu.Delete(id);
        base.SetSuccess("删除成功!");
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "diaocha";
        this.DiaoCha1.Select = "Wenti";
        if (base.Request.QueryString["del"] != null)
        {
            this.delWenti(int.Parse(base.Request.QueryString["del"].ToString()));
        }
        if (base.Request.QueryString["change_show"] != null)
        {
            this.setShow(int.Parse(base.Request.QueryString["change_show"].ToString()), int.Parse(base.Request.QueryString["show"].ToString()));
        }
        this.wenTi();
    }

    private void setShow(int id, int id1)
    {
        Maticsoft.BLL.vote_question _question = new Maticsoft.BLL.vote_question();
        Maticsoft.Model.vote_question model = new Maticsoft.Model.vote_question();
        model = _question.GetModel(id1);
        model.is_show = id;
        _question.Update(model);
    }

    private void updateWenti(int id)
    {
        Maticsoft.Model.vote_question model = new Maticsoft.Model.vote_question();
        foreach (Maticsoft.Model.vote_question _question2 in this.voqu.GetModelList("id=" + id.ToString()))
        {
            model.id = _question2.id;
            model.is_show = int.Parse(base.Request.QueryString["change_show"].ToString());
            model.order = _question2.order;
            model.Title = _question2.Title;
            model.Type = _question2.Type;
        }
        this.voqu.Update(model);
        base.SetSuccess("更新成功！");
    }

    private void wenTi()
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<tr>");
        builder.Append("<th width='40'>ID</th>");
        builder.Append("<th width='500'>标题</th>");
        builder.Append("<th width='50'>状态</th>");
        builder.Append("<th width='100'>排序</th>");
        builder.Append("<th width='200'>操作</th>");
        builder.Append("</tr>");
        StringBuilder builder2 = new StringBuilder();
        Maticsoft.BLL.vote_question _question = new Maticsoft.BLL.vote_question();
        Pagers pagers = DbHelperSQL.SelectByPager("*", "", "Id desc", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, "vote_question", "", "");
        if ((pagers != null) && (pagers.MyData.Rows.Count > 0))
        {
            this.AspNetPager1.RecordCount = pagers.TotalRecords;
            for (int i = 0; i < pagers.MyData.Rows.Count; i++)
            {
                DataRow row = pagers.MyData.Rows[i];
                if ((i % 2) != 0)
                {
                    builder2.Append("<tr>");
                }
                else
                {
                    builder2.Append("<tr class='alt'>");
                }
                builder2.Append("<td>" + row["Id"] + "</td>");
                builder2.Append("<td>" + row["Title"] + "</td>");
                if (Convert.ToInt32(row["is_show"].ToString()) == 1)
                {
                    builder2.Append("<td>显示</td>");
                }
                else
                {
                    builder2.Append("<td>隐藏</td>");
                }
                builder2.Append("<td>" + row["order"] + "</td>");
                builder2.Append("<td class='op'>");
                if (Convert.ToInt32(row["is_show"].ToString()) == 1)
                {
                    builder2.Append("<a href='DiaoCha_Wenti.aspx?change_show=0&show=" + row["Id"] + "'>隐藏</a>｜\t");
                }
                else
                {
                    builder2.Append("<a href='DiaoCha_Wenti.aspx?change_show=1&show=" + row["Id"] + "'>显示</a>｜\t");
                }
                builder2.Append("<a href='DiaoCha_Wenti_Xuanxiang.aspx?id=" + row["Id"] + "'>选项</a>｜\t");
                builder2.Append("<a href='DiaoCha_Wenti_Bianji.aspx?edit=" + row["Id"] + "'>编辑</a>｜\t");
                builder2.Append("<a class=\"remove-record\" href='DiaoCha_Wenti.aspx?del=" + row["Id"] + "''>删除</a>");
                builder2.Append("</td>");
                builder2.Append("</tr>");
            }
        }
        this.Literal1.Text = builder.ToString();
        this.Literal2.Text = builder2.ToString();
    }
}

